import request from '@/utils/request.js';
import { download, toFormData, checkDownloadRes } from '@/utils/common.js';

/**
 * 分页查询就业统计-学生基础信息
 */
export async function pageInfos(params) {
  const res = await request.get(
    '/counsellor/employment/statistic/student/baseInfo/list',
    { params }
  );
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询全部就业统计-学生基础信息
 */
export async function listInfos(params) {
  const res = await request.get(
    '/counsellor/employment/statistic/student/baseInfo/list',
    { params }
  );
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询就业统计-学生基础信息
 */
export async function getInfo(id) {
  const res = await request.get(
    '/counsellor/employment/statistic/student/baseInfo/' + id
  );
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 导出就业统计-学生基础信息
 */
export async function exportInfos(params) {
  const res = await request({
    url: '/counsellor/employment/statistic/student/baseInfo/export',
    method: 'POST',
    data: toFormData(params),
    responseType: 'blob'
  });
  await checkDownloadRes(res);
  download(res.data, `national_employment_system_student_info_${Date.now()}.xlsx`);
}
